home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d16 / pbtool2d.arc / PARSECMD.BAS < prev    next >
BASIC Source File  |  1990-10-29  |  1KB  |  50 lines

  1. 'NumParsCmds - Returns the numer of parameters on command line
  2.  
  3. FUNCTION NumParsCmds%(Cmd$) PUBLIC
  4.    StrLen% = LEN(cmd$)
  5.    FOR I% = 1 TO StrLen%
  6.        Temp$ = MID$(Cmd$,i%,1)
  7.        IF (Temp$ <> " " AND Temp$ <> CHR$(9) AND Temp$ <> "/" AND Temp$<>"-") THEN
  8.           IF NOT Included% THEN
  9.              INCR NumArgs%
  10.              Included% = -1
  11.           END IF
  12.        ELSE
  13.           Included% = 0
  14.        END IF
  15.    NEXT I%
  16.    NumParsCmds%=NumArgs%
  17. END FUNCTION
  18.  
  19. 'ParseCmds - does actual parsing of command line
  20.  
  21. SUB ParseCmds(Cmd$,Args$()) PUBLIC
  22.    StrLen% = LEN(cmd$)
  23.    FOR I% = 1 TO StrLen%
  24.        Temp$ = MID$(Cmd$,i%,1)
  25.        IF (Temp$ <> " " AND Temp$ <> CHR$(9) AND_
  26.            Temp$ <> "/" AND Temp$<>"-") THEN
  27.           IF NOT Included% THEN
  28.              NumArgs% = NumArgs% + 1
  29.              Included% = -1
  30.           END IF
  31.           Args$(NumArgs%) = Args$(NumArgs%) + Temp$
  32.        ELSE
  33.           Included% = 0
  34.        END IF
  35.    NEXT I%
  36. END SUB
  37.  
  38. ' Main Demo
  39. Numargs%=NumParsCmds%(COMMAND$)
  40. DIM Args$(1:Numargs%)
  41. CALL ParseCmds(COMMAND$,Args$())
  42.  
  43.  PRINT "There are";numargs%;"commands on the command line"
  44.  FOR i%= 1 TO numargs%
  45.      PRINT "Argument number";i%;" is:  ";args$(i%)
  46.  NEXT
  47.  END
  48.  
  49. ' This code is based on an example from Berry Erick which was based on
  50. ' and example from Henry Piper.